package com.oa.company.controller;

import com.oa.company.service.CompanyService;


import com.oa.oaspccommon.po.Company;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zd
 * @date 2021年04月14日 15:11
 */
@RestController
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    /**
     * 查询所有company
     * @return
     */
    @RequestMapping(value = "/companys",method = RequestMethod.GET)
    public List<Company> findCompanys(){
        List<Company> list = companyService.findAll();
        return list;
    }

    /**
     * 查询单个company
     * @param cid
     * @return
     */
    @RequestMapping(value = "/company",method = RequestMethod.GET)
    public Company findCompany(@RequestParam("cid") Integer cid){
        return companyService.findOne(cid);

    }

    /**
     * 修改company
     * @param company
     * @return
     */
    @RequestMapping(value = "/company",method = RequestMethod.PUT)
    public Boolean updateCompany(@RequestBody Company company){
        int i = companyService.updateCompany(company);
       if(i>0){
           return true;
       }
       return false;
    }

    /**
     * 添加company
     * @param company
     * @return
     */
    @RequestMapping(value = "/company",method = RequestMethod.POST)
    public Boolean addCompany(@RequestBody Company company){
        int i = companyService.addCompany(company);
        if(i>0){
            return true;
        }
        return false;
    }
}
